<template>
  <el-dialog
    :title="$t('batch.missionManage.form.taskDetails')"
    :visible.sync="open"
    @close="close()"
    width="80%"
    append-to-body
  >
    <div class="discountReceipt-pick-operate-box">
      <!--      <div class="operate-box-top">-->
      <!--        <div class="top-content">-->
      <!--          <Ht-search-form-->
      <!--            :defaultEventKey="defaultEventKey"-->
      <!--            :dictMap="dictMap"-->
      <!--            :queryParams="queryParams"-->
      <!--            :outputQueryParams="queryParams"-->
      <!--            :formOptions="formOptions"-->
      <!--            :advOptions="[]"-->
      <!--            permission="batch:missionManage:view"-->
      <!--          ></Ht-search-form>-->
      <!--        </div>-->
      <!--        </div>-->
      <div class="operate-box-bottom">
        <div class="bottom-content">
          <ht-table
            ref="dataTable"
            :defaultEventKey="defaultEventKey"
            :initData="false"
            :multiSelect="false"
            :dictMap="dictMap"
            :reqConfig="reqConfig"
            :queryParams="queryParams"
            :canHideSearch="false"
            :tableBindColumns="tableBindColumns"
          >
            <template v-slot:operate>
              <el-table-column
                :label="$t('common.operate')"
                align="center"
                width="160"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <ht-button-group
                    :buttonList="[
                      {
                        label: $t('common.check'),
                        permission: 'batch:missionManage:details',
                        doFunc: () => {
                          handleAction('details', scope.row);
                        },
                      },
                      {
                        label: $t('batch.missionManage.form.reRun'),
                        permission: 'batch:missionManage:reRun',
                        doFunc: () => {
                          handleAction('reRun', scope.row);
                        },
                      },
                      {
                        label: $t('batch.missionManage.form.continueRun'),
                        permission: 'batch:missionManage:continueRun',
                        doFunc: () => {
                          handleAction('continueRun', scope.row);
                        },
                      },
                      // {
                      //   label: '取消',
                      //   permission: 'batch:missionManage:cancel',
                      //   doFunc: () => {
                      //     handleAction('cancel', scope.row);
                      //   }
                      // }
                    ]"
                  />
                </template>
              </el-table-column>
            </template>
          </ht-table>
        </div>
      </div>
      <split-details ref="splitDetails"></split-details>
    </div>
  </el-dialog>
</template>

<script>
import {
  apiMissionDetailsUrlConfig,
  cancel,
  nodeReRun,
  nodeContinueRun,
} from "@/api/batch_app/missionManage";
import { listPageMixin } from "@/libs/listPageMixin";
import SplitDetails from "@/views/batch/missionMange/components/SplitDetails";

export default {
  name: "MissionDetails",
  components: { SplitDetails },
  mixins: [listPageMixin],
  data() {
    return {
      defaultEventKey: "md",
      open: false,
      queryParams: {
        flowInstanceId: "",
      },
      formOptions: [],
      reqConfig: apiMissionDetailsUrlConfig,
      // 列信息
      tableBindColumns: [
        { label: `ID`, prop: "id", width: 180 },
        {
          label: this.$t("batch.missionManage.form.nodeCode"),
          prop: "nodeCode",
          width: 160,
        },
        {
          label: this.$t("batch.missionManage.form.startTime"),
          prop: "createTime",
          width: 180,
        },
        {
          label: this.$t("batch.missionManage.form.endTime"),
          prop: "endTime",
          width: 180,
        },
        {
          label: this.$t("batch.missionManage.form.splitCount"),
          prop: "splitCount",
        },
        {
          label: this.$t("batch.missionManage.form.endNodeCount"),
          prop: "finishNodeCount",
        },
        {
          label: this.$t("batch.missionManage.form.status"),
          prop: "status",
          dictCode: "scubb_node_status",
        },
      ],
    };
  },
  mounted() {
    const formOptions = [
      // {
      //   type: "input",
      //   prop: "flowName",
      //   defaultAttr: {
      //     size: "small",
      //     label: "流程名称",
      //     placeholder: "请输入流程名称",
      //   },
      // }
    ];
    this.formOptions = formOptions;
  },
  methods: {
    show(flowInstanceId = "") {
      this.queryParams.flowInstanceId = flowInstanceId;
      // apiMissionDetailsUrlConfig.queryUrl = `${apiMissionDetailsUrlConfig.queryUrl}?flowInstanceId=${flowInstanceId}`
      // apiMissionDetailsUrlConfig.exportUrl = `${apiMissionDetailsUrlConfig.exportUrl}?flowInstanceId=${flowInstanceId}`
      // this.queryParams.nodeCode = nodeCode;
      this.open = true;
      this.$nextTick(() => {
        this.doQuery(this.defaultEventKey);
      });
    },
    close() {
      this.open = false;
    },
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "details":
          this.$refs.splitDetails.show(row.id);
          break;
        case "reRun":
          nodeReRun(row.flowInstanceId, row.id).then((res) => {
            if (res.result) {
              this.$message.success(this.$t("common.operateSuccess"));
            } else {
              this.$message.error(this.$t("common.failure"));
            }
          });
          break;
        case "nodeContinueRun":
          nodeContinueRun(row.flowInstanceId, row.id).then((res) => {
            if (res.result) {
              this.$message.success(this.$t("common.operateSuccess"));
            } else {
              this.$message.error(this.$t("common.failure"));
            }
          });
          break;
        case "cancel":
          this.$confirm(
            this.$t("batch.missionManage.rules.cancelNode"),
            this.$t("common.warning"),
            {
              confirmButtonText: this.$t("common.confirm"),
              cancelButtonText: this.$t("common.cancel"),
              type: "warning",
            }
          )
            .then(function () {
              return cancel(row.flowCode, row.requestId);
            })
            .then(() => {
              this.doQuery(this.defaultEventKey);
              this.msgSuccess(this.$t("common.cancelSuccess"));
            })
            .catch((action) => {});
          break;
      }
    },
  },
};
</script>

<style scoped>
</style>
